﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CCWin;
using GroupChat2013.Entity;
using GroupChat2013.Common;
using GroupChat2013.Logic;
using System.Web;
using GroupChat2013.Service;

namespace GroupChat2013.Main
{
    public partial class FrmGroupNotice : CCSkinMain
    {
        private GroupInfo groupInfo;

        public event Action<string> CompletedHandler;

        public FrmGroupNotice(GroupInfo groupInfo)
        {
            InitializeComponent();

            this.groupInfo = groupInfo;

            this.Load += new EventHandler(FrmGroupNotice_Load);
        }

        void FrmGroupNotice_Load(object sender, EventArgs e)
        {
            lbGroupName.Text = groupInfo.groupName;
            tbNotice.SkinTxt.Text = groupInfo.groupDesc;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                AsyncClient.AsyncCall<bool>(() =>
                {
                    string notice = HttpUtility.UrlEncode(tbNotice.SkinTxt.Text);

                    return ServiceUrlProxy.GetInstance().SetGroupNotice(groupInfo.groupId,
                            EngineContext.Current.CurrUserInfo.CID, notice);
                   
                },
                 (succ) =>
                 {
                     if (succ)
                     {
                         MessageBoxEx.Show("修改成功 ", "提示",
                                   MessageBoxButtons.OK, MessageBoxIcon.Information);

                         if (CompletedHandler != null)
                             CompletedHandler(tbNotice.SkinTxt.Text);

                         this.Close();
                         return;
                     }
                     else
                         MessageBoxEx.Show("修改失败 ", "提示",
                                   MessageBoxButtons.OK, MessageBoxIcon.Information);
                 });
            }
            catch (Exception ex)
            {
                LogHelper.LogError(string.Format("AddGroup()/UpdateGroup()方法 错误信息：{0} 堆栈信息：{1} ", ex.Message, ex.StackTrace));
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
